package com.example.triprec.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.triprec.R;
import com.example.triprec.entity.Scenic;
import com.gzone.university.utils.GlideUtils;

import java.util.List;

public class BannerAdapter extends RecyclerView.Adapter<BannerAdapter.BannerViewHolder> {

    private List<Scenic> scenicList;
    private Context mContext;

    public BannerAdapter(Context context, List<Scenic> imageList) {
        this.mContext = context;
        this.scenicList = imageList;
    }

    @NonNull
    @Override
    public BannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_banner, parent, false);
        return new BannerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BannerViewHolder holder, int position) {
        int realPosition = position % scenicList.size();
        Scenic scenic = scenicList.get(realPosition);

        GlideUtils.load(holder.ivBanner1, scenic.getImageResources()[0]);
        GlideUtils.load(holder.ivBanner2, scenic.getImageResources()[1]);
        GlideUtils.load(holder.ivBanner3, scenic.getImageResources()[2]);
    }

    @Override
    public int getItemCount() {
        return scenicList == null ? 0 : Integer.MAX_VALUE;
    }

    public static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView ivBanner1;
        ImageView ivBanner2;
        ImageView ivBanner3;

        public BannerViewHolder(@NonNull View itemView) {
            super(itemView);
            ivBanner1 = itemView.findViewById(R.id.iv_banner1);
            ivBanner2 = itemView.findViewById(R.id.iv_banner2);
            ivBanner3 = itemView.findViewById(R.id.iv_banner3);
        }
    }
} 